<style>
td {padding:5px 10px;}

</style>
<?php $all_virtual = true; foreach($Carts as $cart) { if(!$cart['Cart']['is_virtual']){$all_virtual=false;break;}  } ?>

<script>

$(function(){
	setInterval(function(){
		var url=BASEURL+'/orders/checkStatus/{{$order_id}}';
		ajaxAction(url,null,null,function(request){
			if( request.status == 1 ) {
				// reload page
				setTimeout(function(){
					window.location = "{{$success_url}}";
					//window.location.reload();
				},2000);
			}
		});
	},3000);
})
</script>

<div>
	<div class="row" style="margin-top:10px;">
	
	{{if !$isWeixin && Configure::read('AliPay.open') && $ali_parameter}}
	<div class="col-sm-6 col-xs-12 text-center">	
			<p style="margin:0;">支付宝扫码支付</p>
		
<iframe frameborder="0" scrolling="no" src="https://mapi.alipay.com/gateway.do?{{http_build_query($ali_parameter)}}" style="border:0 none;margin-left: -15px;" width="320px" height="300px" ></iframe>
		<div  style="margin-top:-30px;">
		{{if Configure::read('AliPay.key')}}
			<form id='alipaysubmit' name='alipaysubmit' action='https://mapi.alipay.com/gateway.do?_input_charset=utf-8' target="_blank" method='get'>
				{{loop $form_parameter $k $v}}
					<input type='hidden' name='{{$k}}' value='{{$v}}'/>
				{{/loop}}
				<input class="btn btn-primary btn-sm" type='submit' value='或使用支付宝账号密码支付'>
			</form>
		{{/if}}
		</div>
	</div>
	{{/if}}

	{{if Configure::read('WechatPay.open')}}
	<div class="col-sm-6 col-xs-12 text-center">
		{{if $isWeixin}}			
			<a class="btn btn-success" href="javascript:void(0)" onclick="callpay()" >微信支付</a>
			<!-- <p style="word-break: break-all;">{{$jsApiParameters}}</p> -->
			<script>
			function jsApiCall()
			{
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest',
					{{$jsApiParameters}},
					function(res){
						if(res.err_msg == "get_brand_wcpay_request:ok" ) {
							  //成功调用
						}
						else{
                            //alert(res.err_code+res.err_desc+res.err_msg);
						}
						//WeixinJSBridge.log(res.err_msg);
						//alert(res.err_desc+res.err_msg);
					}
				);
			}
			
			function callpay()
			{
				if (typeof WeixinJSBridge == "undefined"){
				    if( document.addEventListener ){
				        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
				    }else if (document.attachEvent){
				        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
				        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
				    }
				}else{
				    jsApiCall();
				}
			}
			callpay();
			</script>
		{{else}}
			<p>微信扫码支付</p>
			<div align="center" id="qrcode">
				<img style="width: 240px;height: 240px;" src="/tools/qrcode?uri={{urlencode($wx_qrpay_url)}}">
			</div>
		{{/if}}
	</div>
	{{/if}}
	</div>

	<div class="row" style="margin-top:10px;">
		{{if !$all_virtual}}
		{{template orders/order_consignee}}
		{{/if}}
	<div class="orderinfo col-md-12">
		{{if $orderinfo['Order']['remark']}}
		备注：{{$orderinfo['Order']['remark']}}
		{{/if}}
		<hr/>	
		<div>
		<h4>商品清单</h4>
		<?php $origin_total = 0; ?>
		<div class="p-list">
			<table  class="table">
			<tr><th width="50%">商品名称</th><th>购买价格</th><th>商品数量</th><th class="text-right">合计</th></tr>
			<tbody>
			{{loop $Carts $cart}}
			<tr><td>{{$cart['Cart']['name']}}</td>
			<td><span><small>{{format_price($cart['Cart']['price'])}}</small></span></td>
			<td>{{$cart['Cart']['num']}}</td>
			<td class="text-right">
				<span><small>{{format_price($cart['Cart']['price']*$cart['Cart']['num'])}}</small></span>
				<?php $origin_total += round($cart['Cart']['price']*$cart['Cart']['num'],2); ?>
			</td>		
			</tr>
			{{/loop}}
			</tbody>
			</table>
		</div></div>		
		<!-- template orders/info_wave  -->
		
		<div class="text-right">
			{{if $orderinfo['Order']['ship_fee']>0}}
				<p class="mb10">运费：<span>{{format_price($orderinfo['Order']['ship_fee'])}}</span></p>
			{{/if}}
			
			{{if "$total_price" != "$origin_total"}}
			<p class="mb10"><span>总价：<span style="width: 50px;display: inline-block;text-decoration: line-through;">{{format_price($origin_total)}}</span></span></p>
				<p class="mb10">优惠：<span style="width: 50px;display: inline-block;">{{format_price(round($origin_total-$total_price,2))}}</span></p>
			{{/if}}
			<p class="mb10">合计：<span id="total-price"  class=" product-price">{{format_price($order_total_price)}}</span></p>
		</div>
	</div>
</div>
